home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / Terminal 2.2 / Project / Sources / Monitor.c < prev    next >
Text File  |  1992-01-17  |  2KB  |  133 lines

  1. /*
  2.     Terminal 1.9
  3.     "Monitor.c"
  4. */
  5.  
  6. #ifdef THINK_C
  7. #include "MacHeaders"
  8. #endif
  9. #ifdef applec
  10. #pragma load ":(Objects):MacHeadersMPW"
  11. #pragma segment ZModem
  12. #endif
  13.  
  14. #include "Monitor.h"
  15. #include "FormatStr.h"
  16.  
  17. static short Ref = 0;
  18. static long Start;
  19.  
  20. void MonitorOpen(
  21.     register Byte *name,
  22.     register short vol,
  23.     register long dir)
  24. {
  25.     HParamBlockRec p;
  26.  
  27.     if (Ref)
  28.         return;
  29.  
  30.     p.ioParam.ioCompletion = 0;
  31.     p.ioParam.ioNamePtr = (StringPtr)name;
  32.     p.ioParam.ioVRefNum = vol;
  33.     p.fileParam.ioDirID = dir;
  34.     PBHDelete(&p, FALSE);
  35.  
  36.     p.ioParam.ioCompletion = 0;
  37.     p.ioParam.ioNamePtr = (StringPtr)name;
  38.     p.ioParam.ioVRefNum = vol;
  39.     p.fileParam.ioDirID = dir;
  40.     p.fileParam.ioFVersNum = 0;
  41.     if (PBHCreate(&p, FALSE))
  42.         return;
  43.  
  44.     p.ioParam.ioCompletion = 0;
  45.     p.ioParam.ioNamePtr = (StringPtr)name;
  46.     p.ioParam.ioVRefNum = vol;
  47.     p.fileParam.ioFDirIndex = 0;
  48.     p.fileParam.ioDirID = dir;
  49.     if (PBHGetFInfo(&p, FALSE))
  50.         return;
  51.  
  52.     p.ioParam.ioCompletion = 0;
  53.     p.ioParam.ioNamePtr = (StringPtr)name;
  54.     p.ioParam.ioVRefNum = vol;
  55.     p.fileParam.ioFlFndrInfo.fdType = 'TEXT';
  56.     p.fileParam.ioFlFndrInfo.fdCreator = 'PEDT';
  57.     p.fileParam.ioDirID = dir;
  58.     if (PBHSetFInfo(&p, FALSE))
  59.         return;
  60.     
  61.     p.ioParam.ioCompletion = 0;
  62.     p.ioParam.ioNamePtr = (StringPtr)name;
  63.     p.ioParam.ioVRefNum = vol;
  64.     p.ioParam.ioPermssn = 0;
  65.     p.ioParam.ioMisc = 0;
  66.     p.fileParam.ioFVersNum = 0;
  67.     p.fileParam.ioDirID = dir;
  68.     if (PBHOpen(&p, FALSE))
  69.         return;
  70.     Ref = p.fileParam.ioFRefNum;
  71.     Start = Ticks;
  72. }
  73.  
  74. void MonitorClose(void)
  75. {
  76.     if (Ref) {
  77.         FSClose(Ref);
  78.         Ref = 0;
  79.     }
  80. }
  81.  
  82. void MonitorDump(
  83.     register Byte *buffer,
  84.     long count)
  85. {
  86.     register Byte s[255];
  87.     register Byte b;
  88.     register short n;
  89.     register Byte *max = buffer + count;
  90.     register Byte *p;
  91.     static Byte hex[] = "0123456789ABCDEF";
  92.  
  93.     if (!Ref)
  94.         return;
  95.  
  96.     n = 0;
  97.     p = s;
  98.     while (buffer < max) {
  99.         if (n >= 26) {
  100.             *p++ = '\r';
  101.             count = p - s;
  102.             if (FSWrite(Ref, &count, s)) {
  103.                 MonitorClose();
  104.                 return;
  105.             }
  106.             p = s;
  107.             n = 0;
  108.         }
  109.         b = *buffer++;
  110.         *p++ = ' ';
  111.         *p++ = hex[(b >> 4) & 0x0F];
  112.         *p++ = hex[b & 0x0F];
  113.         ++n;
  114.     }
  115.     *p++ = '\r';
  116.     count = p - s;
  117.     if (FSWrite(Ref, &count, s))
  118.         MonitorClose();
  119. }
  120.  
  121. void MonitorText(Byte *t)
  122. {
  123.     register Byte s[255];
  124.     long count;
  125.  
  126.     if (!Ref)
  127.         return;
  128.     FormatStr(s, (Byte *)"\p%06l: %s\r", Ticks - Start, t);
  129.     count = *s;
  130.     if (FSWrite(Ref, &count, s + 1))
  131.         MonitorClose();
  132. }
  133.